from django.core import validators
from django.core.exceptions import ValidationError
from django.utils.translation import ngettext_lazy
from django.utils.deconstruct import deconstructible
@deconstructible
class MyLength(validators.BaseValidator):
    message = ngettext_lazy(
        "Ensure this value has at most %(limit_value)d character (it has "
        "%(show_value)d).",
        "Ensure this value has at most %(limit_value)d characters (it has "
        "%(show_value)d).",
        "limit_value",
    )
    code = "max_length"

    def compare(self, a, b):
        return a > b

    def clean(self, x):
        return len(x)

def start_with_zzy(value):
    if not value.startswith("zzy"):
        raise ValidationError('必须以zzy开头')
